<?php
namespace Index\Controller;
use Think\Controller;
class CommonController extends Controller {
    public function _initialize()
    {
    	$auth = C('AUTH_CONTROL') ? C('AUTH_CONTROL'): array();


    	foreach ($auth as $v) {
    		if(strtolower(CONTROLLER_NAME)==strtolower($v)){
    			if(!isset($_SESSION['id'])){
		    		$this->error('你没有权限，请先登录',U('index/login/index'));
		    	}
		    	break;
    		}
    	}

    	// var_dump($auth);
    	// CONTROLLER_NAME
    	// in_array(needle, haystack)
    	// if(!isset($_SESSION['id'])){
    	// 	$this->error('你没有权限，请先登录',U('index/login/index'));
    	// }

        if(!S('categorydata')){
            $categorys = M('category')->select();

            S('categorydata',$categorys,30);
        }else{
            $categorys = S('categorydata');
        }
    	

    	$this->assign('categorys',$categorys);
    }
}

